#coding:utf8
from rest_framework import serializers
from .models import Area


class AreaSerialzier(serializers.ModelSerializer):

    class Meta:
        model = Area
        fields = ['id','name']


class SubsAreaSeriazlier(serializers.ModelSerializer):
    # 市 区县的模型数据 用 AreaSerialzier 进行序列化操作
    #area_set = AreaSerialzier(many=True,read_only=True)
    subs = AreaSerialzier(many=True,read_only=True)

    class Meta:
        model = Area
        fields = ['id','name','subs']


"""
省份
[{'id':xxxx,'name':'xxxx'},{'id':xxxx,'name':'xxxx'}]

市  区县
['id':xxx,name:'xxx','subs': [{'id':xxxx,'name':'xxxx'}]]



书籍表
1       三国演义
关联模型类名小写_set =

人物表
11      刘备          1
22      孙尚香        1
33      貂蝉          1

    省份
    10000           北京          None


    市
    10001           北京市         10000


    区县
    10010           昌平区         10001
    10020           海淀区         10001
    10030           朝阳区         10001

"""